<template>
  <div id="app">
    <div id="nav">
      <router-link to="/">Home</router-link>|
      <!-- params /u/200 -->
      <!-- query /u?uid=200 -->
      <router-link :to="{name:'user',params:{uid:'200'}}">用户中心</router-link>|
      <router-link v-bind:to="{name:'about'}">About</router-link>
      <router-link v-bind:to="{name:'store'}">Store</router-link>
    </div>

    <!-- 多个组件需要  transition-group -->
    <!-- 一个组键只需要 transition-->
    <transition-group :name="routerTransition">
      <router-view key="def"/>
      <router-view key="em" name="email"/>
      <router-view key="te" name="tel"/>
    </transition-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      routerTransition: ""
    };
  },
  watch: {
    // 可设定特定路由的动效
    // 监听路由对象的变化
    $route(to) {
      // to当前路由对象
      to.query &&
        to.query.transitionName &&
        (this.routerTransition = to.query.transitionName);
    }
  }
};
</script>


<style>
/* 页面进入时的效果
 页面还没有显示还没显示正在加载 */
.router-enter {
  opacity: 0;
}
.router-enter-active {
  transition: opacity 0.6s ease;
}
.router-enter-to {
  opacity: 1;
}
/* 页面离开时
 */
.router-leave {
  opacity: 1;
}
.router-leave-active {
  transition: opacity 1s ease;
}
.router-leave-to {
  opacity: 0;
}

#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
